import request from '@/utils/request'
import { randomId } from '@/utils'
import memCache from '@/utils/memCache'

// 获取订单列表
export function getOrderList(params) {
  const data = new FormData()
  data.append('page', params.page)
  data.append('rows', params.rows)
  data.append('sort', 'createTime')
  data.append('order', 'desc')
  data.append('filtersRaw', JSON.stringify(params.filtersRaw || []))
  data.append('paramsRaw', JSON.stringify(params.paramsRaw || {}))
  return request({
    method: 'POST',
    url: `/app/v1/order/page`,
    data,
    loading: false
  })
}

// 获取订单详情
export function queryOrderDetail(id) {
  return request({
    method: 'GET',
    url: `/app/v1/order/${id}`
  })
}
/**
 * 提交订单
 * @param {Object} data 订单数据
*/
export function commitOrder(data) {
  return request({
    method: 'POST',
    url: `/app/v1/order/commit`,
    data,
    loading: true,
    message: '正在提交订单'
  })
}

/**
 * 结算-收款
 * @param {String} retailOrderId 订单ID
 * @param {Array} receiptDetails 支付明细
 {
  id:'',
  disCode:'',
  fee:'费用',
  payMode:'支付方式',
  realFee:'',
  receiptId:'',
  remark:'备注'
 }
 **/
export function saveOrderSettlement({ retailOrderId, receiptDetails }) {
  return request({
    method: 'POST',
    url: `/app/v1/order/settlement`,
    data: { retailOrderId, receiptDetails },
    loading: true,
    message: '正在收款'
  })
}

// 获取门店
export function queryStore() {
  return request({
    method: 'GET',
    url: `/app/v1/shopSelector/store`,
    loading: false
  })
}

// 获取当前登录用户的家居顾问岗位
export function queryCurrentShoppingGuide() {
  const data = new FormData()
  data.append('page', 1)
  data.append('rows', 20)
  return request({
    method: 'POST',
    url: `/app/v1/shoppingGuideSelector/currentShoppingGuide`,
    data,
    loading: false
  })
}

// 获取所选门店下的在职家居顾问
export function queryShoppingGuide(params) {
  const data = new FormData()
  data.append('page', params.page)
  data.append('rows', params.pageSize)
  data.append('paramsRaw', JSON.stringify({ 'positionCodes': ['top_shopping_guide'], 'shopCodes': params.shopCodes || [] }))

  return request({
    method: 'POST',
    url: `/app/v1/shoppingGuideSelector/employee/page`,
    data,
    loading: true
  })
}
